package com.boang;

import com.boang.dao.SpuDao;
import com.boang.po.Spu;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;

/*
  @author: 13813
  @date: 2024/7/23 14:11
*/
public class InsertDemo {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();

        SpuDao spuDao = sqlSession.getMapper(SpuDao.class);

        ArrayList<Spu> list = new ArrayList<>();
        list.add(new Spu(1, "华为1", "华为9871"));
        list.add(new Spu(1, "华为2", "华为9872"));
        list.add(new Spu(1, "华为3", "华为9873"));
//        Spu spu = new Spu(1, "华为", "华为987");
        spuDao.insertSpu(list);
        sqlSession.commit();
    }
}
